﻿using System;
using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using com.paypal.sdk.profiles;

using com.paypal.sdk.services;

using log4net;


namespace NETMovie.Prototype.PayPal
{
    
    public partial class WebForm2 : System.Web.UI.Page
    {

        private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        protected void Page_Load(object sender, EventArgs e)
        {

            //com.paypal.sdk.core.APICallerBase.GetCertificate("asasd");
            CallerServices caller = new CallerServices();

            IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();

          //  profile.CertificateFile = "ddf.p12";
                                   
            profile.APIUsername = "jerrtk_1306260751_biz_api1.gmail.com";//"sdk-seller_api1.sdk.com";

            profile.APIPassword = "1306260766";// "12345678";
            profile.Environment = "sandbox";
            //profile.PrivateKeyPassword = "boubabie";
            profile.Subject = "";

           profile.APISignature = "AJvpMaYyn4NFIZlblv2.JkOOwu86A.93rucfL1DgdL31E4czjQSd.LZ6";

            caller.APIProfile = profile;

            com.paypal.soap.api.DoDirectPaymentRequestDetailsType directPaymentDetails =
            new com.paypal.soap.api.DoDirectPaymentRequestDetailsType();



            //Set Credit Card

            com.paypal.soap.api.CreditCardDetailsType cc = new
            com.paypal.soap.api.CreditCardDetailsType();

            cc.CreditCardType = com.paypal.soap.api.CreditCardTypeType.Visa;

            cc.CreditCardNumber = "4153936095299808";

            cc.ExpMonth = 5;

            cc.ExpYear = 2016;
            cc.ExpMonthSpecified = true;
            cc.ExpYearSpecified = true;
            
            //cc.CVV2 = "123";

            //Set Credit Card.CardOwner
         
            com.paypal.soap.api.PayerInfoType theCardOwner = new
            com.paypal.soap.api.PayerInfoType();

            com.paypal.soap.api.PersonNameType thePayerName = new
            com.paypal.soap.api.PersonNameType();

            thePayerName.FirstName = "Vivek";

            thePayerName.LastName = "Doe";

            theCardOwner.PayerName = thePayerName;

            com.paypal.soap.api.AddressType theAddress = new
            com.paypal.soap.api.AddressType();

            theAddress.Street1 = "123 Main";

            theAddress.Street2 = "Apt 23";

            theAddress.CityName = "Hill Side";

            theAddress.StateOrProvince = "";

            theAddress.PostalCode = "32550";

            theAddress.Country = com.paypal.soap.api.CountryCodeType.US;

            theCardOwner.Address = theAddress;

            cc.CardOwner = theCardOwner;

            directPaymentDetails.CreditCard = cc;

            //Set Order Total

            com.paypal.soap.api.BasicAmountType temp = new
            com.paypal.soap.api.BasicAmountType();

            com.paypal.soap.api.PaymentDetailsType payDetailType = new
            com.paypal.soap.api.PaymentDetailsType();

            temp.Value = "50.00";

            temp.currencyID =
            com.paypal.soap.api.CurrencyCodeType.USD; payDetailType.OrderTotal = temp;

            directPaymentDetails.PaymentDetails = payDetailType;

            //Set IP

            directPaymentDetails.IPAddress = "192.168.200.195";

            //Set Transaction Type

            directPaymentDetails.PaymentAction =
            com.paypal.soap.api.PaymentActionCodeType.Sale;



            //Set Request

            com.paypal.soap.api.DoDirectPaymentRequestType request = new
            com.paypal.soap.api.DoDirectPaymentRequestType();

            if (log.IsDebugEnabled)
            {
                log.Debug(request);
            }
         //   com.paypal.sdk.logging.DefaultLogger

            //Set Payment Detail

            request.DoDirectPaymentRequestDetails = directPaymentDetails;



            request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified
            = true;

            com.paypal.soap.api.DoDirectPaymentResponseType response =
            (com.paypal.soap.api.DoDirectPaymentResponseType)caller.Call("DoDirectPayment"

            , request);

            Response.Write("response=" + response.Ack);

         //   Response.Write("response=" + response.Errors[0].LongMessage.ToString() + " - " +
          //  response.Errors[0].ErrorCode.ToString());

        }
    }
}